Project 10:

Output (Transducers/Actuators) Devices: Presenting Sensor (Input) Data through Liquid Crystal Display & Other Devices



Study 01: Making a new PCB using a new Microcontroller & add an Output Device for displaying data

  • 1. Reason behind designing the blinky break-out PCB board for ATTINY 3216:
  • I made a BLINKY board to make sure my board is functioning whenever I am loading a program into my microcontroller (MC) ATTINY 3216. The whole idea was to always include “the blinky code” as a part of my whole sketch. In that case, if my blinky works but not the other input/output devices, then I will understand that my board is functioning but maybe there could be something missing: either correct pin-outs or absence of pull-up resistors or wrong libraries and so on. Top of that, I can use this breakout board with different I/O devices without making new PCBs everytime.

  • 2. Board constituents:
  • That’s why I added a capacitor (between my GRND and VCC) of the ATTINY 8-bit AVR MC. Since it’s a 20 pin MC, I added 2 headers (1x10 pins). But, my pin 19 is connected to the blinky LED only. I also added a 1K ohm resistor with my LED to protect it from getting fried.

  • 3. Need of an adapter:
  • To load the program using FTDI (3.3V) physical interface (or cable), I made a separate ADAPTER. The credit goes to our TA, Andres, who advised me of this and guided me. So, I used Neil’s SERIAL 2- PIN UPDI board trace and outline and made those. I added a 4.9K ohm resistor between the TX pin (of FTDI header) and UPDI pin (of the 2-pin header). The other end of the UPDI trace was connected to the RX pin (of FTDI header).

  • 4. Equivalent Arduino Pin-outs for ATTINY 3216:
  • I collected the equivalent circuit pinouts from CBA’s website. I wanted to check my code with the ARDUINO UNO first and then use the same code for my MC board. I would push the code using the ARDUINO IDE.


  • 5. Need of two (4.7k each) pull-up resistors for LCD module (to display sensor data):
  • I plan to use a LCD module that had a 1602 LCD (Liquid Crystal Display) connected to the I2C serial interface. The LCD screen can display two lines and due to the integrated 12C serial interface, it requires only four pin-outs to interface with Arduino UNO. Although the sketch was working with ARDUINO UNO, it was not working my MC. I talked to my colleagues Collin and he saw that I didn’t have the pull-up resistors between my SDA and SCL pins of the LCD and the corresponding pins, 10 and 11, of my MC. So, I added them and Aastha also helped me out alongside Colin. Colin also helped me to find the correct pins (since it had two different sets of SDA and SCL) using the square waves of the Oscilloscope. We had to calibrate that before using. As sensor, I used the Adafruit’s DHT_11 temperature and humidity sensor that I want to read through the LCD.


  • 6. Library download for LCD:
  • Similar to the step above, I downloaded the “LiquidCrystal_I2C” library from https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library and then put the keypad folder in “Arduino/libraries. In the Arduino IDE, under the menu Sketch-> Include Library > Manage Libraries > Searching for “LiquidCrystal I2c” and I installed it. I installed all the libraries that had the “LiquidCrystal_I2c” added to their name as my sketch was not responding to the one that I installed first. Another approach could be just to install the “New_Liquid_Crystal” one and putting it inside the “Arduino>libraries”: https://drive.google.com/file/d/1Oc56q2GPs5SOA-PdbVHHSxKCnI9KY5xd/view

  • 7. Sketch:
  • Another lab colleague Jin-Hoon helped me alongside with Colin to figure out why my sketch was not working. The reason was, I had multiple libraries inside my pc (ARDUINO > Library) with similar wording “Liquid_Crystal_I2C” on them. So, I compressed those to zip folder so that, my sketch doesn’t try to enter/use them.

  • 8. Correct power voltage supply:
  • Once the code started working, the LCD was not properly displaying the fonts. After looking into the datasheet, I figured out that the LCD needed 4.9-5V power for proper display features. I realized I was connecting my MC board with the 3.3V FTDI cable. So, I immediately changed it and connected to a power source and switched it to 4.9-5V. It works well at 4.9V.


    Video clip:


    Challenges in detail:

    I am trying to use the same Attiny 3216 blinky board (that you saw last week) with a temperature & humidity sensor. However, when I run the sketch (that instructs both the sensor and LED), the sensor doesn't show any value in the serial monitor (although it is taking a 3.3 V when I checked using a multimeter). But the LED keeps blinking based on the sketch, which is a piece of good news (but at a low level of illumination).Contrarily, when I use the same sketch in Arduino Uno, the sensor worked pretty well and the serial monitor also showed the temperature/humidity data.

    Later on, I found the error. The problem was that after I programmed the board using UPDI physical interface, I opened the serial monitor by keeping my UPDI connected to the ATTINY 3216 board. However the DHT_11 needed a power voltage of 3-5V and the connected UPDI was only supplying up to ~3.3V, which might not have been enough for the sensor. Now, once I have disconnected the UPDI and powered it from the ARDUINO 5V port, the serial monitor is responding. So, I need to verify it using a power source and I plan it to do it tomorrow. Unfortunately, I was using a lighjter to warm my sensor and mistakenly I DAMAGED IT WHILE THE FLAME WAS TOO CLOSE TO THE SENSOR. So, I ordered new pairs of DHT_11 sensors and will try them with my theory once they arrive. But, there is a weird problem- the temperature and humidity values are not changing (photo attached). Don't know what to do next to solve it !

    Fortunately, I solved it. The problem was with my libraries. The compiler was reading the wrong libraries because of different libraries with the similar "Liquid_Crystal_I2C" wording on them. Also, I needed to add two pull-up resistors (4.7k ohm each) with my SDA and SCL pins with my PCB - a thing that I didn't realize before. But now, that's solved. Unfortunately, I burnt my sensor with a lighter while working with it. So, I couldn't try my sensor reading on the LCD display. Sorry for that. I am trying to get a new one and will try and will let you know about the final outcome. Now, a new problem surfaced which is the LCD contrast level when I am programming it using my Attiny 3216. I tried adjusting the contrast level of the LCD using the potentiometer embedded in the module, but I am not getting the best display quality, something which wasn't a problem while programming with the Arduino Uno. I have to put in an effort to read what's being displayed on the monitor.

    Again, the problem has been solved. The LCD was not getting the right power voltage. It was getting 3.3 V but it required at least 4.9V - 5V for a good display quality with Attiny 3216. Now, the only thing left is the sensor module.



    Study 02: Adding a Keypad & Displaying data through the LCD

    1. Keypad specifications & other materials for this study: 1. 4×4 keypad matrix
    2. I2C serial interfaced 1602 LCD (Liquid Crystal Display)
    3. Arduino Uno




  • 2. Literature:
  • The circuitry was designed following the article given in Surtr Tech’s website (https://surtrtech.com/) as shown below. To summarize, the pin layout – the pins eight pins (1-8) of the 4X4 membrane keypads are connected to the D9-D2 digital pins of Arduino iUno and the connection of LCD module was pretty straightforward: GND, VCC, SDA and SCL are connected to the GND, 5V, A4, and A5 pins of the Arduino.

  • 3. Downloading library for the keypad:
  • At first, I needed to download the “Keypad” library by Mark Stanley and Alexander from https://playground.arduino.cc/Code/Keypad/. Next, we put the downloaded “Keypad” folder inside “Arduino/libraries.” Then, opening a new sketch from Arduino IDE we import the library (Sketch > Include Library > Manage Libraries > Searching for “Keypad” and installing it). I also installed another library https://github.com/ZulNs/MultitapKeypad

  • 4. Code
  • I used the code that was included in the SURTR Technology’s website to emulate typing the keypad: https://surtrtech.com/2018/01/27/arduino-uno-4x4-keypad-matrix-lcd-i2c-screen/


    Study 03: Display temperature/humidity readings through the LCD

  • 1. Objective:
  • My plan is pretty simple. I wanted to add the sensor to the PCB and display the readings through the LCD display. Since, I used the DHT_11 in the previous works, I plan to use that same one. But first, I want to try with Arduino Uno before I add the circuitries to the ATITNY 3216 board that I made.



  • 2. Code:
  • I combined the codes that I previously used for the sensors/LCD. The pin connections for the LCD remains the same and I connected the DHT_11 sensor to port 2 of Arduino.

    #include // Library for I2C communication
    #include // Library for LCD
    #include // Library for DHT sensors (e.g., DHT_11, _22...)

    dht DHT;

    #define DHT11_PIN 2 // Connecting to Arduino Pin 2 for the DHT_11 sensor
    LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display

    void setup(){
    Serial.begin(9600);
    lcd.init(); // initialize the lcd
    lcd.backlight(); // turn on backlight.
    lcd.begin(16, 2);
    }

    void loop(){
    int chk = DHT.read11(DHT11_PIN);
    lcd.clear();

    lcd.setCursor(0,0);
    lcd.print("Humidity = ");
    lcd.print(DHT.humidity);

    lcd.setCursor(0,1);
    lcd.print("Temp = ");
    lcd.print(DHT.temperature);
    lcd.print(" C") ;

    delay(2000); // We can wait 2 sec (recommended for DHT_11 as its reading changes after each 2 sec)
    //lcd.noBacklight(); // turn off backlight
    //delay(2000);
    //lcd.backlight();
    }


    Study 04: Temperature/humidity sensing and alert user using Piezo buzzer & RGB LED



    Video clip:



  • Code:
  • #include
    dht DHT;

    #define DHT11_PIN 7

    void setup(){
    //Serial Port begin
    Serial.begin (9600);

    //Define inputs and outputs
    pinMode(11, OUTPUT);
    pinMode(10, OUTPUT);
    pinMode(9, OUTPUT);
    pinMode(3, OUTPUT);
    }

    void loop()
    {
    int chk = DHT.read11(DHT11_PIN);
    Serial.print("Temperature = ");
    Serial.println(DHT.temperature);
    Serial.print("Humidity = ");
    Serial.println(DHT.humidity);

    if (DHT.temperature >30) {
    analogWrite(11, 255);//Red
    analogWrite(10, 0);
    analogWrite(9, 0);
    } else if (DHT.temperature >= 25) { // 25 <= temperature < 30
    analogWrite(11, 0);
    analogWrite(10, 255);// Green
    analogWrite(9, 0);
    } else {
    analogWrite(11, 255);
    analogWrite(10, 255);
    analogWrite(9, 0);// Yellow
    }

    if (DHT.temperature >30) {
    tone(3, 165, 1000); // play tone 40 (E3 = 165 Hz)
    }

    delay(100);
    }


    Study 05: Distance sensing using ultrasound and alert user using Piezo buzzer & RGB LED



  • Code:
  • // Standard declaration of pins
    int trigPin = 4; // Trigger from the digital pin
    int echoPin = 5; // Echo in the PWM digital pin
    float duration, distancecm, distanceinches;

    void setup() {
    //Serial Port begin
    Serial.begin (9600);
    //Define inputs and outputs
    pinMode(trigPin, OUTPUT); //triggering a sound to bound off an object
    pinMode(echoPin, INPUT); //receiving the sound bounce (echo) from trigger
    pinMode(11, OUTPUT);
    pinMode(10, OUTPUT);
    pinMode(9, OUTPUT);
    pinMode(3, OUTPUT);
    }

    void loop() {
    // Standard good measure to include this code ensure a clean pulse signal from the sensor
    digitalWrite(trigPin, LOW);
    delay(5);
    digitalWrite(trigPin, HIGH);
    delay(10);
    digitalWrite(trigPin, LOW);

    //setting receiving pin to INPUT again
    pinMode(echoPin, INPUT);
    //duration (in microseconds) it takes for the sound wave to be sent from sensor to object and return
    duration = pulseIn(echoPin, HIGH);

    // Convert the travel time of sound into distance, distance = time x speed of sound
    distancecm = (duration/2) / 29.1; // or multiply (duration/2) by 0.0343 cm/microseconds
    distanceinches = (duration/2) / 74; // or multiply (duration/2) by 0.0135 inch/microseconds and 1 cm = 0,393701 in

    //printing the output in readable form

    Serial.print("Distance: ");
    Serial.print(distancecm);
    Serial.print("cm,");
    Serial.println();

    if (distancecm<5)
    {
    analogWrite(11, 255);
    analogWrite(10, 0);
    analogWrite(9, 0);
    }
    else {
    analogWrite(11, 153);
    analogWrite(10, 255);
    analogWrite(9, 153);
    }

    if (distancecm<5)
    {
    tone(3, 165, 1000); // play tone 40 (E3 = 165 Hz)
    }

    delay(250);
    }

    Study 06: Displaying Message Through an Organic Light Emitting Diode (OLED) device Based on SSD1306 drivers

  • 1. Scanning for I2C address:
  • At first, I connected the pins of the OLED to the corresponding pins in Arduino Uno board. Then, I uploaded a sketch for the i2c_scanner to find my I2C address. The sketch was obtained from https://playground.arduino.cc/Main/I2cScanner/ .This I2C address was used in the “Hello World” sketch for the OLED.

  • 2. Updating the Adrafruit_SSD1306 library in my Mac’s Arduino library:
  • Although, I uploaded the sketch, the OLED screen was not functioning and was frozen with white dots. Later on, I found the reason in our CBA’s Gitlab issue, where @lingdong was mentioning that he had to update the library file that Neil included in the repository. So, I followed the instructions that @lingdong mentioned and it worked. I tried two sketches: (i) a basic “hello world” type sketch, where I programmed the board to display “Hi, it’s Ikra. Welcome to HTMAA!”; and (ii) an example sketch from Arduino (File> Examples > Adafruit SSD 1306 > ssd_1306_128x64_i2c) for a basic animation. But I had to update the I2C address on both cases and changed it to “0x3C” from “0x3D).

    Video clip:



  • Code (to find the I2C address):
  • // --------------------------------------
    // i2c_scanner

    // // Version 1
    // This program (or code that looks like it)
    // can be found in many places.
    // For example on the Arduino.cc forum.
    // The original author is not know.
    // Version 2, Juni 2012, Using Arduino 1.0.1
    // Adapted to be as simple as possible by Arduino.cc user Krodal
    // Version 3, Feb 26 2013
    // V3 by louarnold
    // Version 4, March 3, 2013, Using Arduino 1.0.3
    // by Arduino.cc user Krodal.
    // Changes by louarnold removed.
    // Scanning addresses changed from 0...127 to 1...119,
    // according to the i2c scanner by Nick Gammon
    // https://www.gammon.com.au/forum/?id=10896
    // Version 5, March 28, 2013
    // As version 4, but address scans now to 127.
    // A sensor seems to use address 120.
    // Version 6, November 27, 2015.
    // Added waiting for the Leonardo serial communication.

    #include
    void setup()
    {
    Wire.begin();

    Serial.begin(9600);
    while (!Serial); // Leonardo: wait for serial monitor
    Serial.println("\nI2C Scanner");
    }

    void loop()
    {
    byte error, address;
    int nDevices;
    Serial.println("Scanning...");
    nDevices = 0;
    for(address = 1; address < 127; address++ )
    {

    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
    Serial.print("I2C device found at address 0x");
    if (address<16)
    Serial.print("0");
    Serial.print(address,HEX);
    Serial.println(" !");

    nDevices++;
    }
    else if (error==4)
    {
    Serial.print("Unknown error at address 0x");
    if (address<16)
    Serial.print("0");
    Serial.println(address,HEX);
    }
    }
    if (nDevices == 0)
    Serial.println("No I2C devices found\n");
    else
    Serial.println("done\n");
    delay(5000);
    // wait 5 seconds for next scan

    }